import java.util.Stack;
import javax.microedition.lcdui.*;

public class AppManager {

    private static Display display;
    public static String SERVER;
    private static Stack flow;
    public static mPlayer F_PLAYER;
    private static Stack flowArr;
    public static boolean isSearching = false;
    
    public AppManager() {
    }

    public static void loadApp(Display display) {
        AppManager.display = display;
        SERVER = "http://localhost/musicapp/";
        F_PLAYER = new mPlayer();
        flow = new Stack();
        flowArr = new Stack();
    }
    
    public static void open(Canvas form) {
        flow.push(display.getCurrent());
        flowArr.push("0");
        display.setCurrent(form);
    }
    
    public static void open(Canvas form1, Canvas form2, boolean save){
        if (save){
            flow.push(display.getCurrent());
            flowArr.push("0");
        }
        flow.push(form2);
        flowArr.push("1");
        display.setCurrent(form1);
    }
    
    public static void open(Form form){
        flow.push(display.getCurrent());
        flowArr.push("0");
        display.setCurrent(form);
    }
    
    public static void back(){
        display.setCurrent(null);
        String n = (String)flowArr.pop();
        if (n.equals("1")){
            flow.pop();
            flowArr.pop();
        }
        display.setCurrent((Displayable)flow.pop());
    }
    public static void backSearch(){
        flow.pop();
        flowArr.pop();
        flow.pop();
        flowArr.pop();
    }
    public static void swap(){
        Canvas tmp = (Canvas)display.getCurrent();
        display.setCurrent((Displayable)flow.pop());
        flow.push(tmp);
    }
}